import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:get/get_state_manager/get_state_manager.dart';
import 'package:yp/pages/mall_app/draw_bill_detail/state.dart';

import 'logic.dart';

class DrawBillDetailPage extends StatefulWidget {
  DrawBillDetailPage({Key key}) : super(key: key);

  @override
  _DrawBillDetailPageState createState() {
    return _DrawBillDetailPageState();
  }
}

class _DrawBillDetailPageState extends State<DrawBillDetailPage> {
  final DrawBillDetailController logic = Get.put(DrawBillDetailController());

  final DrawBillDetailState state = Get.find<DrawBillDetailController>().state;
  // DrawBillDetailController controller = Get.put(DrawBillDetailController());
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Color(0xfff5f5f5),
      appBar: AppBar(
        centerTitle: true,
        backgroundColor: Color(0xffEA5504),
        elevation: 0,
        title: Text('发票详情'),
      ),
      body: GetBuilder<DrawBillDetailController>(
        init: DrawBillDetailController(),
        builder: (logic) {
          return state.info == null
              ? Container()
              : Container(
                  padding: EdgeInsets.symmetric(horizontal: 30.w),
                  child: Column(
                    children: [
                      Container(
                        padding: EdgeInsets.symmetric(vertical: 30.w),
                        decoration: BoxDecoration(
                          border: Border(
                            bottom: BorderSide(
                              color: Color(0xfff3f3f3),
                            ),
                          ),
                          color: Colors.white,
                        ),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.start,
                          children: [
                            Container(
                              width: 150.w,
                              child: Text(
                                "发票状态",
                                style: TextStyle(color: Colors.black54),
                              ),
                            ),
                            Text(
                                "${_getStatusText(state.info['status_num_id'])}"),
                          ],
                        ),
                      ),
                      Container(
                        padding: EdgeInsets.symmetric(vertical: 30.w),
                        decoration: BoxDecoration(
                          border: Border(
                            bottom: BorderSide(
                              color: Color(0xfff3f3f3),
                            ),
                          ),
                          color: Colors.white,
                        ),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.start,
                          children: [
                            Container(
                              width: 150.w,
                              child: Text(
                                "发票类型",
                                style: TextStyle(color: Colors.black54),
                              ),
                            ),
                            Text(state.info["invoice_type"] == 2
                                ? "企业"
                                : "个人/非公司"),
                          ],
                        ),
                      ),
                      Container(
                        padding: EdgeInsets.symmetric(vertical: 30.w),
                        decoration: BoxDecoration(
                          border: Border(
                            bottom: BorderSide(
                              color: Color(0xfff3f3f3),
                            ),
                          ),
                          color: Colors.white,
                        ),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.start,
                          children: [
                            Container(
                              width: 150.w,
                              child: Text(
                                "发票抬头",
                                style: TextStyle(color: Colors.black54),
                              ),
                            ),
                            Text("${state.info["invoice_title"]}"),
                          ],
                        ),
                      ),
                      Container(
                        padding: EdgeInsets.symmetric(vertical: 30.w),
                        decoration: BoxDecoration(
                          border: Border(
                            bottom: BorderSide(
                              color: Color(0xfff3f3f3),
                            ),
                          ),
                          color: Colors.white,
                        ),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.start,
                          children: [
                            Container(
                              width: 150.w,
                              child: Text(
                                "发票内容",
                                style: TextStyle(color: Colors.black54),
                              ),
                            ),
                            Text(
                                "${state.info["consumer_invoice_content"] == '' ? '商品明细' : state.info["consumer_invoice_content"]}"),
                          ],
                        ),
                      ),
                      Container(
                        padding: EdgeInsets.symmetric(vertical: 30.w),
                        decoration: BoxDecoration(
                          border: Border(
                            bottom: BorderSide(
                              color: Color(0xfff3f3f3),
                            ),
                          ),
                          color: Colors.white,
                        ),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.start,
                          children: [
                            Container(
                              width: 150.w,
                              child: Text(
                                "收票邮箱",
                                style: TextStyle(color: Colors.black54),
                              ),
                            ),
                            Text("${state.info["taker_email"]}"),
                          ],
                        ),
                      ),
                    ],
                  ),
                );
        },
      ),
    );
  }

  _getStatusText(int status) {
    if (status == 1) {
      return '待开票';
    }
    if (status == 2) {
      return '已开票';
    }
    if (status == 3) {
      return '开票中';
    }
    if (status == 4) {
      return '开票失败';
    }
    if (status == 9) {
      return '已作废';
    }

    return '';
  }
}
